<html>
<head><meta charset="utf-8"><title>Potential stabilization of valid_range attributes · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html">Potential stabilization of valid_range attributes</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193150828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193150828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193150828">(Apr 07 2020 at 07:49)</a>:</h4>
<p>Hi,<br>
I think <code>rustc_layout_scalar_valid_range_start, rustc_layout_scalar_valid_range_end, rustc_nonnull_optimization_guaranteed</code> have proved themselves quite useful and a clever use of rust's safety guarantees. <br>
I think these(probably under different names?) can be of great service to users/libraries outside of libcore too.<br>
And because they require unsafe to write into the object I think they won't be too easily misused.<br>
for example, I can Imagine NonNegative <code>i32</code> being used quite often, and will have more than 1 bit for niche.</p>
<p>Would love to hear what do people think and if the strong wording against this being ever stabilized are just because it's a rustc attribute or for some other/deeper reason.</p>



<a name="193188073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193188073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193188073">(Apr 07 2020 at 13:35)</a>:</h4>
<p>I feel that this functionality is better exposed with const generics than attributes. It would essentially be an expanded version of <code>NonZero</code>.</p>



<a name="193228164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193228164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193228164">(Apr 07 2020 at 18:25)</a>:</h4>
<p>Hmm sounds interesting, how would that look like?</p>



<a name="193275062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193275062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193275062">(Apr 08 2020 at 04:34)</a>:</h4>
<p>I found myself wanting this as well, recently. I have some large data structures that could be optimized by creating specialized types that have large niches.</p>



<a name="193283887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193283887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193283887">(Apr 08 2020 at 07:35)</a>:</h4>
<p>How far is const generics from being ready for stable? How far is this set of attributes from being something that could be ready for stable? Probably, attributes would be a lot more practical a lot sooner.</p>



<a name="193312150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193312150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193312150">(Apr 08 2020 at 12:36)</a>:</h4>
<p><code>RangeU32&lt;min: u32, max: u32&gt;</code></p>



<a name="193321737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Potential%20stabilization%20of%20valid_range%20attributes/near/193321737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Potential.20stabilization.20of.20valid_range.20attributes.html#193321737">(Apr 08 2020 at 13:46)</a>:</h4>
<p>See also <a href="https://github.com/rust-lang/rfcs/pull/2888" title="https://github.com/rust-lang/rfcs/pull/2888">https://github.com/rust-lang/rfcs/pull/2888</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>